#! /usr/bin/python
# _*_ coding:UTF-8 _*_

import numpy as np
import matplotlib.pyplot as plt
import svmMLiA

if __name__ == "__main__":
    print "star"
    # data_set = np.loadtxt("testSet.txt", delimiter="\t", dtype=float)
    xcord0 = []
    ycord0 = []
    xcord1 = []
    ycord1 = []
    markers = []
    colors = []
    fr = open('testSet.txt')
    for line in fr.readlines():
        lineSplit = line.strip().split('\t')
        xPt = float(lineSplit[0])
        yPt = float(lineSplit[1])
        label = int(lineSplit[2])
        if (label == -1):
            xcord0.append(xPt)
            ycord0.append(yPt)
        else:
            xcord1.append(xPt)
            ycord1.append(yPt)
    fr.close()
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.scatter(xcord0, ycord0, marker='s', s=50)
    ax.scatter(xcord1, ycord1, marker='o', s=50, c='red')
    plt.title('Support Vectors Circled')
    # plt.show()
    (dataArr, labelArr) = svmMLiA.loadDataSet("testSet.txt")
    (b, alphas) = svmMLiA.smoSimple(dataArr, labelArr, 0.6, 0.001, 40)
    # print type(labelArr)
    labelArr = np.array(labelArr).reshape((100, 1))
    omga = (np.multiply(alphas, labelArr)).T * dataArr
    print omga
    print omga[0, 0]
    x = np.arange(2, 7.0, 0.1)
    # print np.size(x)
    y = (-omga[0, 0] * x - b) / omga[0, 1]
    # y = (-0.8 * x - (-3.7)) / (-0.27)
    # print y.tolist()[0]
    ax.plot(x, y.tolist()[0])
    # ax.axis([-2, 12, -8, 6])
    plt.show()
    # print omga